<div class="formElements">
    <div class="padding20px">
        <?php /*
          <div class="common">
          <div class="col">
          <input type="text" class="field" placeholder="Enter Name">
          </div>
          </div>
          <div class="common">
          <div class="col">
          <input type="text" class="field" placeholder="Enter Email">
          </div>
          </div> */ ?>
        <input type="hidden" id='user_review_id' value="<?php echo $profiles->user_id; ?>">
         <input type="hidden" id='user_review_userType' value="<?php echo $userType; ?>">
        <div class="common">
            <div class="col">
                <textarea placeholder="Write Your Review" name="TrainerProfileReview['reviews_text']" id="reviews_text" onkeyup ="countChar(this);"></textarea>
                <div class="errorMessage" id="error_reviews_text"></div>
                <div id="charNum" class="errorMessage"></div>
            </div>
        </div>
        <input type="button" class="btn twoBtn" value="Submit" id="submitLbtR"><a id="cancelRbtn" href="#" class="btn">Cancel</a>

    </div>
</div>
<script type="text/javascript" src="<?php echo ThemePath(); ?>/js/jquery.lightbox_me.js"></script>

<script>

function openLoginReview(){
$.magnificPopup.open({
    items: [{src: '#loginPopReview', type: 'inline'} ],
    gallery: {enabled: true},
	mainClass: 'mfp-fade',
	removalDelay: 160,
    type: 'image'
    });
}

</script>

<script>
    function countChar(val) {
        var len = val.value.length;
        if (len >= 600) {
            val.value = val.value.substring(0, 600);
            $('#charNum').text('You can type max 600 char.');
        } else {
            $('#charNum').text('');
        }
    }
</script>
<script>
    $("#submitLbtR").click(function() {
        var text = $("#reviews_text").val();
        var userId = $("#user_review_id").val();
        var userType = $("#user_review_userType").val();
        if (text == '') {
            $("#error_reviews_text").text('Please Write Your Review.');
        } else {
            $.post("<?php echo Yii::app()->createUrl("TrainerProfileReview/create"); ?>", {userId: userId, text: text, userType: userType}, function(result) {
                if ($.trim(result) == 'redirect') {
					openLoginReview();
					return false;
                }
                
                if ($.trim(result) == 'againsameuser') {
					$("#reviews_text_success").hide();
					$("#reviewDiv").hide();
					$("#reviewEntryBox").show();
					$("#error_reviews_text").show();
					$("#error_reviews_text").text("You you have already made a query for this trainer.").show();
					return false;
                }
				
				if ($.trim(result) == 'fail') {
                    $("#error_reviews_text").text("You can't give own review.");
                }
                else {
                    $("#reviewEntryBox").hide();
                    $("#reviewDiv").show();
                    $("#reviews_text_success").text(result);
                }
            });
        }
    })

</script>

